using System;
using System.Collections.Generic;
using SouthernLand.Common.DAL;
using SouthernLand.Common.DAL.NhaDat;

namespace SouthernLand.Common.BOL.NhaDat
{
    public class Categories
    {
        #region Public Properties

        public Int32 CateID { get; set; }

        public DateTime AddedDate { get; set; }

        public String AddedBy { get; set; }

        public String AppKey { get; set; }

        public String Title { get; set; }

        public String Title_en { get; set; }

        public String Description { get; set; }

        public String Description_en { get; set; }

        public String ImageUrl { get; set; }

        public Int32 DisplayOrder { get; set; }

        public Int32 ParentID { get; set; }

        public Boolean IsActive { get; set; }

        public static string GetCateNameByCateID(Int32 CateID)
        {
            try
            {
                Categories obj = GetCategoriesByID(CateID);
                return (Globals.LangVietNam()) ? obj.Title : obj.Title_en;
            }
            catch
            {
                return "";
            }
        }

        public static List<Categories> GetCategoriesByParentID(Int32 ParentID)
        {
            var db = new CategoriesDAL();
            return db.GetCategoriesByParentID(ParentID);
        }

        #endregion

        #region public static Methods

        public static string GetCateNameByID(int ID)
        {
            try
            {
                Categories obj = GetCategoriesByID(ID);
                return Globals.GetLang(obj.Title, obj.Title_en);
            }
            catch
            {
                return "";
            }
        }

        // dem so tin moi nhat theo ngay
        public static int GetCountArticlesByDate(int CateID)
        {
            try
            {
                return ClassData.ReturnInteger("Exec w4u_Categories_GetCountArticlesByDate @CateID = " + CateID);
            }
            catch
            {
                return 0;
            }
        }

        public static int Insert(Categories obj)
        {
            var db = new CategoriesDAL();
            return db.Insert(obj);
        }

        public static bool Update(Categories obj)
        {
            var db = new CategoriesDAL();
            return db.Update(obj);
        }

        public static bool Delete(Int32 CateID)
        {
            Categories obj = GetCategoriesByID(CateID);
            FileProcess.DeleteFile(Globals.PhysicalApplicationPath() + "UserUpload/Categories/" + obj.ImageUrl);
            var db = new CategoriesDAL();
            return db.Delete(CateID);
        }

        public static Categories GetCategoriesByID(Int32 CateID)
        {
            var db = new CategoriesDAL();
            return db.GetCategoriesByID(CateID);
        }

        //Get All Categories
        public static List<Categories> GetAllCategories()
        {
            var db = new CategoriesDAL();
            return db.GetAllCategories(1, 10000);
        }

        //Get All Categories
        public static List<Categories> GetAllCategories(int PageIndex, int PageSize)
        {
            var db = new CategoriesDAL();
            return db.GetAllCategories(PageIndex, PageSize);
        }

        // Get Count All records of Table  Categories
        public static int GetCountCategories()
        {
            var db = new CategoriesDAL();
            return db.GetCountCategories();
        }

        #endregion
    }
}